﻿using System;

namespace BuilderPattern;

//建造者模式
public class Product
{
    public string? PartA { get; set; }
    public string? PartB { get; set; }
    public string? PartC { get; set; }

    public void Display()
    {
        Console.WriteLine($"PartA:{PartA},\nPartB:{PartB},\nPartC:{PartC}");
    }
}

public abstract class Builder
{
    public abstract void BuildPartA();
    public abstract void BuildPartB();
    public abstract void BuildPartC();
    public abstract Product GetResult();
}

public class ConcreteBuilder : Builder
{
    private readonly Product _product = new();

    public override void BuildPartA()
    {
        _product.PartA = "实际组件A";
    }

    public override void BuildPartB()
    {
        _product.PartB = "实际组件B";
    }

    public override void BuildPartC()
    {
        _product.PartC = "实际组件C";
    }

    public override Product GetResult()
    {
        return _product;
    }
}

public class Director(Builder builder)
{
    public void Construct()
    {
        builder.BuildPartA();
        builder.BuildPartB();
        builder.BuildPartC();
    }
}

public static class Program
{
    public static void Main()
    {
        Builder builder = new ConcreteBuilder();
        Director director = new Director(builder);

        director.Construct();

        Product product = builder.GetResult();
        product.Display();
    }
}